<template>
  <div class="focus">
    <hmheader title='我的关注'>
      <span slot="left"
            class="iconfont iconjiantou2"
            @click="$router.back()"></span>
    </hmheader>
    <div class="list">
      <div class="box"
           v-for='(item,index) in followList'
           :key='item.id'>
        <img :src="item.head_img"
             alt="">
        <div class="center">
          <p>{{item.nickname}}</p>
          <span>{{item.create_date | singledateFormat('-')}}</span>
        </div>
        <span @click="cancelFollowUser(item.id,index)">取消关注</span>
      </div>
    </div>
  </div>
</template>

<script>
import hmheader from '@/components/hmheader.vue'
import { getUserFollows, unfollowUser } from '@/apis/user.js'
import axios from '@/utils/myaxios.js'
import { singledateFormat } from '@/utils/myfilters.js'
export default {
  components: {
    hmheader
  },
  data () {
    return {
      followList: []
    }
  },
  methods: {
    async cancelFollowUser (id, index) {
      let res = await unfollowUser(id)
      console.log(res);
      this.$toast.success(res.data.message)
      // 页面的刷新
      this.followList.splice(index, 1)
    }
  },
  async activated () {
    let res = await getUserFollows()
    console.log(res);
    // 对数据进行改造
    this.followList = res.data.data.map(v => {
      v.head_img = axios.defaults.baseURL + v.head_img
      return v
    })
  },
  filters: {
    singledateFormat
  }
}
</script>

<style lang='less' scoped>
.list {
  .box {
    display: flex;
    padding: 25px 10px;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #ccc;
    > img {
      display: block;
      width: 50/360 * 100vw;
      height: 50/360 * 100vw;
      border-radius: 50%;
      padding: 0 10px;
    }
    > .center {
      flex: 1;
      > p {
        line-height: 30px;
        font-size: 14px;
      }
      > span {
        font-size: 12px;
        color: #999;
      }
    }
    > span {
      height: 30px;
      background-color: #eee;
      font-size: 13px;
      border-radius: 30px;
      line-height: 30px;
      padding: 0px 15px;
    }
  }
}
</style>
